﻿using npljobs.JobAlertService.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace npljobs.JobAlertService
{
    /// <summary>
    /// Job alert service is a windows service to periodically send emails the users.
    /// The service sends the email to the registered jobseeker's  according to their preference 
    /// It can send email to the user based on their frequency settings i.e. daily/weekly/monthly
    /// </summary>
    public partial class JobAlertService : ServiceBase
    {

        private System.Timers.Timer timer;


        public JobAlertService()
        {
            InitializeComponent();
            

        }

        public void RunService()
        {
            CreateAlertJob alert = new CreateAlertJob();
            alert.SendJobs();
        }

        protected override void OnStart(string[] args)
        {
            this.timer = new System.Timers.Timer(30000D);  // 30000 milliseconds = 30 seconds
            this.timer.AutoReset = true;
            this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_Elapsed);
            this.timer.Start();
        }

        protected override void OnStop()
        {
            this.timer.Stop();
            this.timer = null;
        }

        private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            
        }
    }
}
